package com.sino.business.service;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.sino.bean.Basicinfo;
import com.sino.bean.Sharepeople;
import com.sino.business.ISharePeopleService;
import com.sino.dao.IBasicInfoDAO;
import com.sino.model.SharePeopleModel;

public class SharePeopleServiceImp implements ISharePeopleService{
	private IBasicInfoDAO basicInfoDAO = null;
	/**
     * Description       	   ：保存其他共有专利人信息到数据库中
     * @param sharePeopleModel ：其他共有专利人基础类
     */
	public void saveSharePeople(SharePeopleModel sharePeopleModel){
		Sharepeople[] sharepeoples = this.getSharepeople(sharePeopleModel);
		Sharepeople sharePeople;
		for(int i = 0 ; i<6 ; i++){
			sharePeople = sharepeoples[i];
			this.getBasicInfoDAO().saveSharePeople(sharePeople);
		}
	}
	/**
     * Description       	   ：更新其他共有专利人信息到数据库中
     * @param sharePeopleModel ：其他共有专利人基础类
     */
	public void updateSharePeople(SharePeopleModel sharePeopleModel){}
	/**
     * Description       	   ：根据专利Id查找专利共有人信息
     * @param zlId	     	   ：专利Id
     */
	public SharePeopleModel findSharePeople(String zlId){
		List temp = this.getBasicInfoDAO().findSharePeople(zlId);
		return this.getSharePeopleModel(temp);
	}
	
	//---------------------------------数据转换
	public Sharepeople[] getSharepeople(SharePeopleModel sharePeopleModel){
		Basicinfo basicInfo = new Basicinfo();
		basicInfo.setZlid(sharePeopleModel.getZlId());
		
		Sharepeople[] sharePeople = {new Sharepeople(),new Sharepeople(),new Sharepeople(),new Sharepeople(),new Sharepeople(),new Sharepeople()};
		
		sharePeople[0].setId(sharePeopleModel.getId1());
		sharePeople[0].setLxdh(sharePeopleModel.getLxdh1());
		sharePeople[0].setLxr(sharePeopleModel.getLxr1());
		sharePeople[0].setBasicinfo(basicInfo);
		
		sharePeople[1].setId(sharePeopleModel.getId2());
		sharePeople[1].setLxdh(sharePeopleModel.getLxdh2());
		sharePeople[1].setLxr(sharePeopleModel.getLxr2());
		sharePeople[1].setBasicinfo(basicInfo);
		
		sharePeople[2].setId(sharePeopleModel.getId3());
		sharePeople[2].setLxdh(sharePeopleModel.getLxdh3());
		sharePeople[2].setLxr(sharePeopleModel.getLxr3());
		sharePeople[2].setBasicinfo(basicInfo);
		
		sharePeople[3].setId(sharePeopleModel.getId4());
		sharePeople[3].setLxdh(sharePeopleModel.getLxdh4());
		sharePeople[3].setLxr(sharePeopleModel.getLxr4());
		sharePeople[3].setBasicinfo(basicInfo);
		
		sharePeople[4].setId(sharePeopleModel.getId5());
		sharePeople[4].setLxdh(sharePeopleModel.getLxdh5());
		sharePeople[4].setLxr(sharePeopleModel.getLxr5());
		sharePeople[4].setBasicinfo(basicInfo);
		
		sharePeople[5].setId(sharePeopleModel.getId6());
		sharePeople[5].setLxdh(sharePeopleModel.getLxdh6());
		sharePeople[5].setLxr(sharePeopleModel.getLxr6());
		sharePeople[5].setBasicinfo(basicInfo);
		return sharePeople;
		
	}
	public SharePeopleModel getSharePeopleModel(List sharepeopleList){
		SharePeopleModel sharePeopleModel = new SharePeopleModel();
		Iterator it = sharepeopleList.iterator();
		Sharepeople sharepeople;
		int i = 1;
		while(it.hasNext()){
			sharepeople = (Sharepeople)it.next();
			try{
				BeanUtils.copyProperty(sharePeopleModel, "id"+i, sharepeople.getId());
				BeanUtils.copyProperty(sharePeopleModel, "lxr"+i, sharepeople.getLxr());
				BeanUtils.copyProperty(sharePeopleModel, "lxdh"+i, sharepeople.getLxdh());
				i++;
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}

		return sharePeopleModel;
	}
	//	---------------------------------接口
	public IBasicInfoDAO getBasicInfoDAO() {
		return basicInfoDAO;
	}
	public void setBasicInfoDAO(IBasicInfoDAO basicInfoDAO) {
		this.basicInfoDAO = basicInfoDAO;
	}
}
